﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Yss.KFlow;
using Yss.KFlow.Util;
using System.ComponentModel;
namespace Yss.KFlow.Data
{
    /// <summary>
    /// 流程控件的形状
    /// </summary>
    [Serializable ]
    public class Shape
    {

        //private int key=-1;

        //public int Key
        //{
        //    get { return key; }            
        //}


        //private Shape prec, next;

        //public Shape Next
        //{
        //    get { return next; }
        //    set { next = value; }
        //}

        //public Shape Prec
        //{
        //    get { return prec; }
        //    set { prec = value; }
        //}
        
         Bitmap pic;
        /// <summary>
        ///  图片
        /// </summary>
         public Bitmap Pic
         {
             get { return pic; }
             set
             {

                 pic = value;
                 BasePic = value;
             }
         }
         private Bitmap basePic;
         public Bitmap BasePic
         {
             get
             {
                 return basePic;
             }
             set
             {
                 basePic = value;
             }
         }
         public void SetPicSize ( Size s )
         {
             if ( pic == null )
             {
                 return;
             }
             if ( s . Height < 5 || s . Width < 5 )
             {
                 return;
             }
             pic = new Bitmap ( basePic  , s );
             Point p = this . locationP;
             this . locationP = new Point ( 0 , 0 );
             this . locationP = p;

         }

        private bool selected = false;
        /// <summary>
        /// 控件是否处于选中状态
        /// </summary>
        [Browsable (false )]
        public bool Selected
        {
            get { return selected; }
            set { selected = value; }
        }

        Point locationP;

        /// <summary>
        /// 图片的初始位置
        /// </summary>
        [Browsable(false)]
        public Point LocationP
        {
            get { return locationP; }
            set 
            {
                if ( value . X < 10 || value . Y < 10 )
                {
                    return;
                }
                if ( value . X < 10 || value . Y < 10 )
                {
                    return;
                }
                if (locationP !=new Point (0,0))
                {
                    oldApexPionts = apexPionts;
                }
                locationP = value;
                apexPionts[0] = value;                
                apexPionts[1] = new Point(value.X + pic.Width / 2 , value.Y);
                apexPionts[2] = new Point(value.X + pic.Width, value.Y);
                apexPionts[3] = new Point(value.X, value.Y + pic.Height / 2 );
                apexPionts[4] = new Point(value.X + pic.Width, value.Y + pic.Height / 2 );
                apexPionts[5] = new Point(value.X, value.Y + pic.Height);
                apexPionts[6] = new Point(value.X + pic.Width / 2 , value.Y + pic.Height);
                apexPionts[7] = new Point(value.X + pic.Width, value.Y + pic.Height);
                //if (key == -1)
                //{
                //    key = Common.PicKey++;
                //}


            }

        }
        /// <summary>
        /// 显示是需要突出显示的8个顶点
        /// </summary>
        Point[] apexPionts = new Point[8];
        /// <summary>
        /// 显示是需要突出显示的8个顶点
        /// </summary>
        [Browsable(false)]
        public Point[] ApexPionts
        {
            get { return apexPionts; }
            set { apexPionts = value; }
        }
        /// <summary>
        /// 旧的顶点个顶点
        /// </summary>
        [Browsable(false)]
        Point[] oldApexPionts = new Point[8];
        /// <summary>
        /// 旧的顶点
        /// </summary>
        [Browsable(false)]
        public Point[] OldApexPionts
        {
            get { return oldApexPionts; }
            set { oldApexPionts = value; }
        }


        ///// <summary>
        ///// 上顶点连线
        ///// </summary>
        //Stack<Line> upLine = new Stack<Line>();
        ///// <summary>
        ///// 上顶点连线
        ///// </summary>
        //public Stack<Line> UpLine
        //{
        //    get { return upLine; }
        //    set { upLine = value; }
        //}
        //Stack<Line> downLine = new Stack<Line>();
        ///// <summary>
        ///// 下顶点连线
        ///// </summary>
        //public Stack<Line> DownLine
        //{
        //    get { return downLine; }
        //    set { downLine = value; }
        //}
        //Stack<Line> leftLine = new Stack<Line>();
        ///// <summary>
        ///// 坐顶点连线
        ///// </summary>
        //internal Stack<Line> LeftLine
        //{
        //    get { return leftLine; }
        //    set { leftLine = value; }
        //}
        ///// <summary>
        ///// 又顶点连线
        ///// </summary>
        //Stack<Line> rightLine = new Stack<Line>();

        //internal Stack<Line> RightLine
        //{
        //    get { return rightLine; }
        //    set { rightLine = value; }
        //}
       ///// <summary>
       // ///  默认图片构造
       ///// </summary>
       ///// <returns></returns>
       // public Bitmap MakeBitmap()
       // {
           
       //     Pic = new Bitmap((Image)Resource.test1 , new Size(40, 40));
       //     return Pic;
       // }

        private object tag = null;
        /// <summary>
        /// 用户自定义对象
        /// </summary>
        public object Tag
        {
            get { return tag; }
            set { tag = value; }
        }
        /// <summary>
        /// 矩形数据对象
        /// </summary>
        public Shape()
        {
          
            //MakeBitmap();
            
                        
        }
        /// <summary>
        /// 得到图片中心坐标
        /// </summary>
        public Point GetMiddleP
        {
            get
            {              
                return new Point(locationP.X + Pic.Width / 2, locationP.Y + Pic.Height / 2);
            }
        }     
       
    }
}
